﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XYX.Print.Models;

namespace XYX.Print.Client.PrintUI
{
    public partial class BatteryPrintForm : UIForm
    {
        public BatteryPrintForm()
        {
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]//应用API函数  
        private static extern bool BitBlt(
        IntPtr hdcDest, // 目标设备的句柄    
        int nXDest, // 目标对象的左上角的X坐标    
        int nYDest, // 目标对象的左上角的X坐标    
        int nWidth, // 目标对象的矩形的宽度    
        int nHeight, // 目标对象的矩形的长度    
        IntPtr hdcSrc, // 源设备的句柄    
        int nXSrc, // 源对象的左上角的X坐标    
        int nYSrc, // 源对象的左上角的X坐标    
        System.Int32 dwRop // 光栅的操作值    
        );
        Image memoryImage; //统计报表画图 

      
        private Battery model = new Battery
        {
            Date = "2022年3月",
            LJH="",
        };


        private void BV06_1_Load(object sender, EventArgs e)
        {
            this.uiPanel1.FillColor = Color.FromArgb(245, 245, 245);
            this.uiPanel1.RectColor = Color.FromArgb(215, 215, 215);
            this.lab_Date.Text = model.Date;

            lblLJH.Text = model.LJH;
            lblWXCC.Text = model.WXCC;
            lblCPXH.Text = model.CPXH;
            lblLX.Text = model.LX;
            lblBCDY.Text = model.BCDY;
            lblDCRL.Text = model.DCRL;
            lblGJJ.Text = "关键件" + model.GJJ;
        }

        private void btn_print_Click(object sender, EventArgs e)
        {
            Graphics graphic = uiPanel1.CreateGraphics();
            Size s = uiPanel1.Size;
            Bitmap memImage = new Bitmap(s.Width, s.Height, graphic);
            Graphics memGraphic = Graphics.FromImage(memImage);
            IntPtr dc1 = graphic.GetHdc();
            IntPtr dc2 = memGraphic.GetHdc();
            BitBlt(dc2, 0, 0, uiPanel1.ClientRectangle.Width, uiPanel1.ClientRectangle.Height,
            dc1, 0, 0, 13369376);

            memoryImage = (Bitmap)memImage.Clone();
            graphic.ReleaseHdc(dc1);
            memGraphic.ReleaseHdc(dc2);
            graphic.Dispose();
            memGraphic.Dispose();
            memImage.Dispose();


            PrintPreviewDialog dlg = new PrintPreviewDialog();
            printDocument1.Print();
            this.Close();
        }

        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 100);
        }
    }
}
